package dp.onClass.class3.exer02;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // 课程数
        int m = sc.nextInt(); // 天数
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = sc.nextInt();
            }
        }
        // 1. 状态初始化dp[i][j]表示到第i门课程剩余j+1天的最大利润
        int[][] dp = new int[n][m];
        // 2. 状态初始化
        dp[0][0] = arr[0][0];
        for (int i = 1; i < m; i++) {
            dp[0][i] = Math.max(arr[0][i], dp[0][i - 1]);
        }
        // 3. 状态转移
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < m; j++) {
                for (int k = 0; k <= j; k++) {
                    if (k < j) {
                        dp[i][j] = Math.max(dp[i][j], arr[i][k]	+ dp[i - 1][j - k - 1]);
                    } else {
                        dp[i][j] = Math.max(dp[i][j], arr[i][k]);
                    }
                }
            }
        }
        // 4. 返回值
        int maxValue = -1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                maxValue = Math.max(maxValue, dp[i][j]);
            }
        }
        System.out.println(maxValue);
    }
}
